using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TowerDefence
{
    public class BulletManager
    {
        public static List<Bullet> mBulletList=new List<Bullet>();

        public static Bullet CreatButtle(string modelName)
        {
            if (mBulletList.Count > 0)
            {
                for (int i = 0; i < mBulletList.Count; i++)
                {
                    if (mBulletList[i].gameObject.activeSelf == false&&mBulletList[i].name==modelName)
                    {
                        mBulletList[i].gameObject.SetActive(true);
                        return mBulletList[i];
                    }
                }
            }

            GameObject obj;
            if (string.IsNullOrEmpty(modelName))
            {
                obj = new GameObject();
                
            }
            else
            {
                obj = Resources.Load<GameObject>($"Model/{modelName}");
                obj = GameObject.Instantiate(obj);
            }
           
               obj.name = modelName;
                   
                Bullet bullet = obj.AddComponent<Bullet>();
                mBulletList.Add(bullet);
                return bullet;
            
        }
    }
}

